<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\URL;

/**
 * 运营者身份判断中间件
 *
 * @author YYJ
 * Class Operator
 * @package App\Http\Middleware
 */
class Operator
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (auth('admin')->user()->isRoot() || auth('admin')->user()->isManager()) {
            $previousUrl = URL::previous();
            return response()->view('admin.errors.403', compact('previousUrl'));
        }

        return $next($request);
    }
}
